#!/bin/sh
# chkconfig: 123456 90 10
# brownie server for fairylucky

# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.


workdir=/fairylucky/brownie

brownie_start(){
	cd $workdir
	echo "brownie is starting"
	nohup python brownie_server.py 10000 > brownie_server.pl 2>&1 &
	echo "brownie started"
}

brownie_stop(){
	pids=`ps -ef | grep 'brownie_server.py' | awk '{ print $2 }'`
    echo $pids
    arr=($pids)
    
    for p in ${arr[@]}
    do
        kill -9 $p
    done
    sleep 2
    echo "Server killed."
}


case "$1" in
    start)
		brownie_start
        ;;
    stop)
        brownie_stop
        ;;
	restart|reload)
		brownie_stop
		sleep 0.3
		brownie_start
		;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac
